/************************************************************************************************
 * test examples of 100 interesting program in C
 * test 055.c
 * duty of doctors
 ***********************************************************************************************/

#include <stdio.h>
#include <string.h>

/*
 * this program is about the test,
 * but result is same as the original problem,
 * so is the method.
 */

#define DOC_A 0
#define DOC_B 1
#define DOC_C 2
#define DOC_D 3
#define DOC_E 4
#define DOC_F 5
#define DOC_G 6

#define MON 0
#define TUE 1
#define WED 2
#define THU 3
#define FRI 4
#define SAT 5
#define SUN 6

int main()
{
	int duty[7];
	int doctor[7];
	memset(doctor, 0, sizeof(int)*7);
	memset(duty, 0, sizeof(int)*7);
	doctor[DOC_F] = THU;
	duty[doctor[DOC_F]] = 1;

	int i = 0;
	for (i = MON; i <= SUN; i++)
	// Doctor A
	{
		if (duty[i] == 1) continue;
		doctor[DOC_A] = i;
		duty[i] = 1;
		doctor[DOC_C] = (i+7-1) % 7;
		if (duty[doctor[DOC_C]] != 1)
		{
			duty[doctor[DOC_C]] = 1;
			int j = 0;
			for (j = MON; j <= SUN; j++)
			// Doctor D
			{
				if (duty[j] == 1) continue;
				doctor[DOC_D] = j;
				duty[j] = 1;
				doctor[DOC_E] = (j+7-2) % 7;
				if (duty[doctor[DOC_E]] != 1)
				{
					duty[doctor[DOC_E]] = 1;
					int k = 0;
					for (k = MON; k <= SUN; k++)
					// Doctor B
					{
						if (duty[k] == 1) continue;
						// F is between B & C
						if (!((k < THU && doctor[DOC_C] > THU) || (k > THU && doctor[DOC_C] < THU))) continue;
						doctor[DOC_B] = k;
						duty[k] = 1;
						doctor[DOC_G] = (k+7+3) % 7;
						if (duty[doctor[DOC_G]] != 1)
						{
							int p = 0;
							for (p = 0; p < 7; p++)
								printf("%3d", doctor[p]);
							printf("\n");
						}
						duty[k] = 0;
					}
					duty[doctor[DOC_E]] = 0;
				}
				duty[j] = 0;
			}
			duty[doctor[DOC_C]] = 0;
		}
		duty[i] = 0;
	}
}

